package com.example.demo.dto;

import com.example.demo.enums.OrderPriorityEnum;
import com.example.demo.enums.OrderStatusEnum;
import com.example.demo.enums.OrderTypeEnum;
import com.example.demo.enums.PaymentMethodEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 订单响应DTO
 * 
 * 演示功能：
 * 1. 枚举字段自动序列化为code值
 * 2. 前端接收到的是数字，而非枚举名称
 * 3. 减少网络传输数据量，提升性能
 */
@Data
@ApiModel(description = "订单信息")
public class OrderDTO {
    
    @ApiModelProperty(value = "订单ID")
    private Long id;
    
    @ApiModelProperty(value = "订单编号")
    private String orderNo;
    
    @ApiModelProperty(value = "用户ID")
    private Long userId;
    
    @ApiModelProperty(value = "订单状态代码", example = "1", notes = "1-待支付, 2-已支付, 3-备货中, 4-已发货, 5-已送达, 6-已完成, 7-已取消, 8-退款中, 9-已退款")
    private OrderStatusEnum status;
    
    @ApiModelProperty(value = "订单状态名称", example = "待支付")
    private String statusText;
    
    @ApiModelProperty(value = "订单类型代码", example = "1", notes = "1-普通订单, 2-预售订单, 3-团购订单, 4-秒杀订单, 5-礼品订单")
    private OrderTypeEnum type;
    
    @ApiModelProperty(value = "订单类型名称", example = "普通订单")
    private String typeText;
    
    @ApiModelProperty(value = "优先级代码", example = "2", notes = "1-低优先级, 2-普通优先级, 3-高优先级, 4-紧急优先级")
    private OrderPriorityEnum priority;
    
    @ApiModelProperty(value = "优先级名称", example = "普通优先级")
    private String priorityText;
    
    @ApiModelProperty(value = "支付方式代码", example = "1", notes = "1-支付宝, 2-微信支付, 3-银行卡, 4-信用卡, 5-余额支付, 6-货到付款")
    private PaymentMethodEnum paymentMethod;
    
    @ApiModelProperty(value = "支付方式名称", example = "支付宝")
    private String paymentMethodText;
    
    @ApiModelProperty(value = "订单总金额")
    private BigDecimal totalAmount;
    
    @ApiModelProperty(value = "实付金额")
    private BigDecimal paidAmount;
    
    @ApiModelProperty(value = "收货地址")
    private String shippingAddress;
    
    @ApiModelProperty(value = "收货人姓名")
    private String receiverName;
    
    @ApiModelProperty(value = "收货人电话")
    private String receiverPhone;
    
    @ApiModelProperty(value = "订单备注")
    private String remark;
    
    @ApiModelProperty(value = "支付时间")
    private LocalDateTime paidTime;
    
    @ApiModelProperty(value = "发货时间")
    private LocalDateTime shippedTime;
    
    @ApiModelProperty(value = "完成时间")
    private LocalDateTime completedTime;
    
    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createdTime;
    
    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updatedTime;
    
    @ApiModelProperty(value = "是否可以取消")
    private Boolean canCancel;
    
    @ApiModelProperty(value = "是否可以退款")
    private Boolean canRefund;
    
    @ApiModelProperty(value = "是否在线支付")
    private Boolean isOnlinePayment;
    
    /**
     * 设置枚举文本字段
     */
    public void setEnumTexts() {
        if (status != null) {
            this.statusText = status.value();
        }
        if (type != null) {
            this.typeText = type.value();
        }
        if (priority != null) {
            this.priorityText = priority.value();
        }
        if (paymentMethod != null) {
            this.paymentMethodText = paymentMethod.value();
        }
    }
}
